var express = require('express');
var router = express.Router();
var db = require('../sql.js');

/* GET users listing. */
router.get('/', function(req, res, next) {
  var id = req.query.id;
  db.query(`delete from banner where id = ${id}`,function(err,result){
    if(err){
      console.log(err);
      return;
    }

    db.query('select * from banner',function(err,result){
        var pager = {};
        // 当前页码
        pager.pageCurrent = 1;
        // 总条数
        pager.maxNum = result.length;
        // 每页条数
        pager.pageSize = 5;
        // 总页数
        pager.pageCount = parseInt(Math.ceil(pager.maxNum / pager.pageSize));
        // 页码列表
        var dataList = result.slice((pager.pageCurrent - 1) * pager.pageSize, (pager.pageCurrent - 1) * pager.pageSize + pager.pageSize);
    
        if(err){
          console.log(err);
          return;
        }
        // console.log(result);
        res.render('bannerList',{
          bannerList:dataList,
          pager:pager
        })
    
      })

  })
});
module.exports = router;
